<template>
    <div id="myChart" :style="{width: '1024px', height: '600px'}"></div>
</template>

<script>

export default {
  name: "charts",
  data() {
    return {

    };
  },
    mounted(){
    this.drawLine();
  },
  created() {

  },
  methods: {
        drawLine(){
        // 基于准备好的dom，初始化echarts实例
        let myChart = this.$echarts.init(document.getElementById('myChart'))
        // 绘制图表
        myChart.setOption({
       title: {
            text: '关联关系图'
        },
        // 提示框的配置
        tooltip: {
            formatter: function (x) {
                return x.data.des;
            }
        },
        // 工具箱
        toolbox: {
            // 显示工具箱
            show: true,
            feature: {
                mark: {
                    show: true
                },
                // 还原
                restore: {
                    show: true
                },
                // 保存为图片
                saveAsImage: {
                    show: true
                }
            }
        },

        series: [{
            type: 'graph', // 类型:关系图
            layout: 'force', //图的布局，类型为力导图
            symbolSize: 40, // 调整节点的大小
            roam: true, // 是否开启鼠标缩放和平移漫游。默认不开启。如果只想要开启缩放或者平移,可以设置成 'scale' 或者 'move'。设置成 true 为都开启
            edgeSymbol: ['circle', 'arrow'],
            edgeSymbolSize: [2, 10],
            edgeLabel: {
                normal: {
                    textStyle: {
                        fontSize: 20
                    }
                }
            },
            force: {
                repulsion: 2500,
                edgeLength: [10, 50]
            },
            draggable: true,
            lineStyle: {
                normal: {
                    width: 2,
                    color: '#4b565b',
                }
            },
            edgeLabel: {
                normal: {
                    show: true,
                    formatter: function (x) {
                        return x.data.name;
                    }
                }
            },
            label: {
                normal: {
                    show: true,
                    textStyle: {}
                }
            },
 
            // 数据
            data: [{
                name: 'node01',
                des: 'nodedes01',
                symbolSize: 70,
                category: 0,
            }, {
                name: 'IBM存储',
                des: 'nodedes02',
                symbolSize: 50,
                category: 1,
            }, {
                name: 'ORACLE',
                des: 'nodedes3',
                symbolSize: 50,
                category: 1,
            }, {
                name: 'APACHE',
                des: 'nodedes04',
                symbolSize: 50,
                category: 1,
            }, {
                name: 'ESXI6.0',
                des: 'nodedes05',
                symbolSize: 50,
                category: 1,
            }],
            links: [{
                source: 'node01',
                target: 'ESXI6.0',
                name: '安装于',
                des: 'link01des'
            }, {
                source: 'node01',
                target: 'IBM存储',
                name: '连接',
                des: 'link02des'
            }, {
                source: 'node01',
                target: 'ORACLE',
                name: '依赖于',
                des: 'link03des'
            }, {
                source: 'node01',
                target: 'APACHE',
                name: '依赖于',
                des: 'link05des'
            }],
        }]

        });
    }
  },
};
</script>

<style lang="scss" scoped>

</style>
